package com.wanmait.CarTrading.DAO.impl;

import com.wanmait.CarTrading.DAO.CarTypeDAO;
import com.wanmait.CarTrading.Util.DBHelper;
import com.wanmait.CarTrading.Util.Pager;
import com.wanmait.CarTrading.vo.Cartype;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
@Repository("carTypeDAO")
public class CarTypeDAOImpl implements CarTypeDAO {

    public List<Cartype> findAll(){
        Cartype cartype=null;
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        List<Cartype> cartypes=new ArrayList();
        String sql=" Select * from cartype  ";

        try {
            conn= DBHelper.getDBhelper().getConn();
            ps=conn.prepareStatement(sql);

            rs=ps.executeQuery();

            while(rs.next()) {
                cartype = new Cartype();
                cartype.setCarTypeName(rs.getString("car_type_name"));
                cartype.setId(rs.getInt("id"));


                cartypes.add(cartype);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            DBHelper.getDBhelper().close(rs,ps,conn);
        }
        return cartypes;
    }

    @Override
    public Cartype findById(Integer id) {
        return null;
    }

    @Override
    public List<Cartype> findAll(Pager pager) {
        return null;
    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public void insert(Cartype object) {

    }

    @Override
    public void update(Cartype object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }
}
